//
//  Omron.m
//  CocOmron
//
//  Created by Paul Hubbard on 5/29/08.
//  Copyright 2008 SDSC. All rights reserved.
//

#import "Omron.h"
#import <OmronFramework/OmronUSB.h>

@implementation Omron

// Button pressed!
- (IBAction) detect:(id)sender
{
    NSMutableData *data = NULL;
    BOOL          result = FALSE;
    
    
    [textOut setObjectValue:@"Searching..."];
    [progressSpinner startAnimation:self];

    OmronUSB *pedometer = [OmronUSB new];
    
    result = [pedometer detect];

    [progressSpinner stopAnimation:self];

    if(result == NO)
    {
        [textOut setObjectValue:@"Omron not found, sorry... Press Detect to try again."];
        return;
    }
    
    [textOut setObjectValue:@"Omron found, trying runloop..."];
    [progressSpinner startAnimation:self];
        
    data = [pedometer getReport:0];
    
    [progressSpinner stopAnimation:self];

    if(data != NULL)
        [textOut setObjectValue:@"Runloop OK"];
    else
        [textOut setObjectValue:@"Runloop failed"];
}


// Work done on startup
- (void)awakeFromNib
{
    // Clear output textarea
    resultString = [NSString new];
    
    // And data dump area
    [dataOut setObjectValue:resultString];
    
//    [tableView 
}


@end
